package cn.tedu.ivoscm.dict.controller;

import cn.tedu.ivoscm.base.response.JsonResult;
import cn.tedu.ivoscm.dict.pojo.dto.DictQuery;
import cn.tedu.ivoscm.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivoscm.dict.pojo.vo.DictVO;
import cn.tedu.ivoscm.dict.service.DictService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dict")
@Api(tags = "04.字典管理")
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("select")
    public JsonResult select(DictQuery dq) {
        log.debug("开始处理查询字典列表请求，参数：{}", dq);
        List<DictVO> list = dictService.select(dq);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(@RequestBody DictSaveParam dsp) {
        log.debug("开始处理保存字典请求，参数：{}", dsp);
        dictService.save(dsp);
        return JsonResult.ok();
    }

    @DeleteMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理删除字典请求，参数：{}", id);
        dictService.deleteById(id);
        return JsonResult.ok();
    }
}
